<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 用户输入一个整数n，计算n的阶乘。即n*(n-1)*(n-2)*……*3*2*1. -->

    <script type="text/javascript">
        var n = parseInt(prompt("请输入一个整数", 5));
        var sum = 1;
        // var num = n
        // while (num) {
        //     sum *= num;
        //     num--
        // alert(n + '的阶乘:' + sum)
        // }
        for (var i = n; i > 0; i--) {
            sum *= i
        }
        alert("n的阶乘为" + sum);
    </script>
</body>

</html>